//
//  commentsViewController.m
//  sleepTest2
//
//  Created by apple on 2017/8/5.
//  Copyright © 2017年 apple. All rights reserved.
//

#import "commentsViewController.h"
#import <objc/runtime.h>
#import <objc/message.h>
#import "subViewController.h"
// 宏定义颜色
#define bgColor [UIColor colorWithRed:34/255.0 green:38/255.0 blue:65/255.0 alpha:1]
#define lightBlueColor [UIColor colorWithRed:113/255.0 green:123/255.0 blue:172/255.0 alpha:1]
#define whiteBlueColor [UIColor colorWithRed:188/255.0 green:195/255.0 blue:232/255.0 alpha:1]



@interface commentsViewController ()

@end

@implementation commentsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    
    // 设置标题和背景颜色：
    self.title = @"意见反馈";
    self.view.backgroundColor = bgColor;
    
    // 意见反馈label
    UILabel *commentsLabel = [[UILabel alloc] init];
    commentsLabel.frame = CGRectMake(10, 70, [UIScreen mainScreen].bounds.size.width, 35);
    commentsLabel.text = @"问题或建议";
    commentsLabel.textColor = lightBlueColor;
    commentsLabel.font = [UIFont systemFontOfSize:20];
    [self.view addSubview:commentsLabel];
    
    // 通过运行时，发现UITextView有一个叫做“_placeHolderLabel”的私有变量
    unsigned int count = 0;
    Ivar *ivars = class_copyIvarList([UITextView class], &count);
    for (int i = 0; i < count; i++) {
        Ivar ivar = ivars[i];
        const char *name = ivar_getName(ivar);
        NSString *objcName = [NSString stringWithUTF8String:name];
        NSLog(@"%d : %@",i,objcName);
    }
    [self setupTextView];
    
    // 联系方式label
    UILabel *telLaber = [[UILabel alloc] initWithFrame:CGRectMake(10, 300, [UIScreen mainScreen].bounds.size.width, 35)];
    telLaber.text = @"联系方式";
    telLaber.textColor = lightBlueColor;
    telLaber.font = [UIFont systemFontOfSize:20];
    [self.view addSubview:telLaber];
    
    // 联系方式textField
    UITextView *telTextField = [[UITextView alloc] init];
    telTextField.frame = CGRectMake(10, 335, [UIScreen mainScreen].bounds.size.width, 35);
    telTextField.backgroundColor = bgColor;
    telTextField.text = @"+86 15657672333";
    telTextField.textColor = lightBlueColor;
    [self.view addSubview:telTextField];
    
    // 调用自定义导航栏
    [self initNavButton];
    
    
}

// 自定义导航栏按钮
- (void)initNavButton{
    UIButton *navButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, 50, 32)];
    [navButton setTitle:@"提交" forState:UIControlStateNormal];
    [navButton setTitleColor:[UIColor purpleColor] forState:UIControlStateNormal];
    [navButton addTarget:self action:@selector(pushAction) forControlEvents:UIControlEventTouchUpInside];
    // 把按钮添加到导航栏上
    UIBarButtonItem *item = [[UIBarButtonItem alloc] initWithCustomView:navButton];
    self.navigationItem.rightBarButtonItem = item;
}

// 定义按钮点击事件
- (void)pushAction{
    subViewController *subVC = [[subViewController alloc] init];
    [self presentViewController:subVC animated:YES completion:nil];
    
}


// 设置意见textview
- (void)setupTextView{
    // 初始化UITextView
    UITextView *commentsTextView = [[UITextView alloc] initWithFrame:CGRectMake(10, 105, [UIScreen mainScreen].bounds.size.width - 10, 250)];
    commentsTextView.backgroundColor = [UIColor colorWithRed:34/255.0 green:38/255.0 blue:65/255.0 alpha:1];
        [self.view addSubview:commentsTextView];
    
    // _placeholderLabel
    UILabel *placeHolderLabel = [[UILabel alloc] init];
    placeHolderLabel.text = @"请尽可能详细地描述你遇到的问题或建议，我们将尽快反馈，并致力于为你提供完整的服务。";
    placeHolderLabel.numberOfLines = 0;
    [placeHolderLabel sizeToFit];
    [commentsTextView addSubview:placeHolderLabel];
    
    //  设置字号
    commentsTextView.font = [UIFont systemFontOfSize:15.f];
    placeHolderLabel.font = [UIFont systemFontOfSize:13.f];
    
    // 设置颜色
    commentsTextView.textColor = [UIColor colorWithRed:188/255.0 green:195/255.0 blue:232/255.0 alpha:1];
    placeHolderLabel.textColor = [UIColor colorWithRed:113/255.0 green:123/255.0 blue:172/255.0 alpha:1];
    
    [commentsTextView setValue:placeHolderLabel forKey:@"_placeholderLabel"];
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
